<?php
namespace src\logic;
class lcoreutil {
	/**
	 * 手机号码的信息屏蔽展示
	 * @param string $mobile
	 * @return string
	 */
	public static function mobileFilter($mobile) {
		if (!lverify::is_mobile($mobile)) {
			return '';
		}
		$len    = 5;
		$mobile = substr($mobile, 0, 3).str_repeat('*', $len+1).substr($mobile, 0-$len);
		return $mobile;
	}
	
	/**
	 * 邮箱号码的资料信息屏蔽展示
	 * @param string $email
	 * @return string 
	 */
	public static function emailFilter($email) {
		if (!lverify::is_email($email)) {
			return '';
		}
		list($username, $subfix) = explode('@', $email);
		$len    = strlen($username);
		if ($len > 4) {
			$email  = substr($username, 0, $len - 4).str_repeat('*', 4).'@'.$subfix;
		} else {
			$email  = str_repeat('*', $len).'@'.$subfix;
		}
		return $email;
	}
	
	/**
	 * 设置时区返回日期格式
	 * @param string $email
	 * @return string 
	 */
	public static function timezone($timestamp, $zone = 'America/Vancouver', $suffix = 'PST') {
		$date = new DateTime();
		$date->setTimezone(new DateTimeZone($zone));
		$date->setTimestamp($timestamp);
		return $date->format('Y-m-d H:i:s').' '.$suffix;
	}
}